<?php
	namespace app\advert\admin;

	use app\admin\controller\Admin;
	use app\common\builder\ZBuilder;
	use think\Db;

	class Index extends Admin
	{
		//广告分组
		public function advGroup(){
			$data = Db::name('advert_group')->select();
			return 	ZBuilder::make('table')
					->addColumns([
						['id','编号'],
						['name','分组名称'],
						['remark','备注'],
						['right_button','操作']
					])
					->addTopButton('add',['href'=>url('addGroup')])
					->addRightButtons(['edit','delete'])
					->setRowList($data)
					->fetch();
		}
		//添加分组
		public function addGroup(){
			if($this->request->isPost()){
				$data = $this->request->post();
				$groupId = Db::name('advert_group')->insertGetid($data);
				if($groupId){
					return $this->success('添加成功',url('advert/index/advGroup'));
				}else
				{
					return $this->error('添加失败',url('advert/index/addGroup'));
				}
			}else
			{
				return 	ZBuilder::make('form')
					->addFormItems([
						['text','name','分组名称'],
						['text','remark','备注']
					])
					->layout(['name'=>4,'remark'=>8])
					->fetch();
			}
			
		}
	}
	